﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExitPanel : MonoBehaviour
{
    public static ExitPanel instance;
    private void Awake()
    {
        instance = this;
    }
    public static void Show()
    {
        if (instance)
        {
            instance.gameObject.SetActive(true);
        }
    }
    public static void Hide()
    {
        if (instance)
        {
            instance.gameObject.SetActive(false);
        }
    }
    private void Start()
    {
        ExitPanel.Hide();
    }

    public Rect rc_win;
    public GUIStyle windowStyle;

    public Rect rc_label;
    public Rect rc_bt_canfirm;
    public Rect rc_bt_cancel;
    public GUIStyle labelStyle;
    public GUIStyle buttonSytle;

    private void DrawWindow(int id)
    {
        GUI.Label(rc_label, "确认要退出游戏吗?", labelStyle);
        if(GUI.Button(rc_bt_canfirm, "确认", buttonSytle))
        {
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
        if(GUI.Button(rc_bt_cancel, "取消", buttonSytle))
        {
            ExitPanel.Hide();
        }
    }

    private void OnGUI()
    {
        GUI.ModalWindow(3, rc_win, DrawWindow, "", windowStyle);
    }
}
